package wch;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * This tests for variability in bullet power administered by the robot DaRumble.
 * 
 * @author Christopher Wilson
 */
public class TestDaRumbleFiring extends RobotTestBed {

  // In order to see if DaRumble is firing bullets at different powers;
  private boolean varyingPower = false;

  /**
   * Specifies that Crazy and DaRumble are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {

    return "sample.Crazy,wch.DaRumble";
  }

  /**
   * This test runs for 20 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {

    return 20;
  }

  /**
   * At the end of each turn, checks the power of all bullets moving across the battlefield. Checks
   * to see if there is any variability in bullet power, proving that DaRumble is using proportional
   * firing based on distance of detected enemy robot.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {

    // All active bullets belong to DaRumble since SittingDuck does not fire.
    IBulletSnapshot bullets[] = event.getTurnSnapshot().getBullets();
    double firePower;
    for (int i = 0; i < bullets.length; i++) {
      firePower = bullets[i].getPower();
      if (firePower <= 3.0 && firePower > 1.8) {
        varyingPower = true;
      }
      if (firePower <= 1.8 && firePower > 0.1) {
        varyingPower = true;
      }
    }
  }

  /**
   * After running all matches, determine if DaRumble has had variability in its bullet power.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {

    assertTrue("Bullet Power flucuates", varyingPower);

  }
}